<?php

/**
 * Manages the views in the application.
 *
 * @author Niels Janssen
 * @since 2009-04-20
 */
class ViewManager
{
	
	/**
	 * The views that are managed in this container.
	 *
	 * @var array
	 */
	private $views = array();
	
	/**
	 * Pushes a view onto the stack.
	 *
	 * @param View $view
	 */
	public function push( View $view )
	{
		$this->views[] = $view;
	}
	
	/**
	 * Removes a view from the stack.
	 *
	 * @param View $view
	 */
	public function remove( View $view )
	{
		foreach( $this->views as $i => $compareView )
		{
			if( $compareView == $view )
			{
				unset( $this->views[ $i ] );
			}
		}
	}
	
	/**
	 * Render the views to the page.
	 *
	 * @return string
	 */
	public function render()
	{
		$stack = '';
		
		foreach( $this->views as $view )
		{
			$stack .= $view->render();
		}
		
		return $stack;
	}
}